package com.vesystem.vegua.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @auther hcy
 * @create 2020-12-11 17:48
 * @Description
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/user/userLogin")
                .excludePathPatterns("/appIcon/**")
                .excludePathPatterns("/remoteApp/goToRemotePage")
                .excludePathPatterns("/static/**")
               // .excludePathPatterns("/**")
        ;
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        //映射图标文件夹
        registry.addResourceHandler("/appIcon/**")
                .addResourceLocations("file:"+GlobalConfig.BASE_PATH + GlobalConfig.BASE_PATH_ABOUT_ICON);
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedMethods("POST","GET","DELETE","PUT");
    }
}
